//
//  CustomerTableViewCell.m
//  Kfangchan
//
//  Created by liran on 14/11/7.
//  Copyright (c) 2014年 Beijing Renjuren Network Technology Co., Ltd. All rights reserved.
//

#import "CustomerTableViewCell.h"

@interface CustomerTableViewCell()

@property (strong, nonatomic) Customer *customer;

@property (strong, nonatomic) IBOutlet UILabel *nameLabel;
@property (strong, nonatomic) IBOutlet UILabel *mobileLabel;
@property (strong, nonatomic) IBOutlet UILabel *remarkLabel;
@property (strong, nonatomic) IBOutlet UILabel *buildingLabel;

@end

@implementation CustomerTableViewCell

- (void)awakeFromNib {
    UIImageView *line = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"partition.png"]];
    line.frame = CGRectMake(0, 84, 320, 0.5);
    [self.contentView addSubview:line];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

#pragma mark -
#pragma mark 封装cell
- (void)initCell:(Customer *)entity {
    self.customer = entity;
    
    self.nameLabel.text = self.customer.name;
    self.mobileLabel.text = self.customer.mobile;
    self.remarkLabel.text = [NSString stringWithFormat:@"备注：%@", self.customer.remark];
    self.buildingLabel.text = [NSString stringWithFormat:@"推荐楼盘：%@", self.customer.lastBuilding.building.name];
    CGRect rect =  [self.buildingLabel textRectForBounds:self.buildingLabel.frame limitedToNumberOfLines:0];
    CGSize size = rect.size;
    self.buildingLabel.size = size;
    
    NSString *statusName = self.customer.lastBuilding.statusName2;
    if (statusName == nil || statusName.length == 0) {
        return;
    }
    UIButton *statusButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [statusButton setBackgroundImage:[UIImage imageNamed:@"customer_status.png"] forState:UIControlStateNormal];
    statusButton.userInteractionEnabled = NO;
    if (statusName.length == 2) {
        statusButton.size = CGSizeMake(38, 17);
    } else {
        statusButton.size = CGSizeMake(48, 17);
    }
    [statusButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [statusButton setTitle:statusName forState:UIControlStateNormal];
    statusButton.titleLabel.font = [UIFont systemFontOfSize:12];
    statusButton.titleEdgeInsets = UIEdgeInsetsMake(0, 2, 0, -5);
    statusButton.origin = CGPointMake(self.buildingLabel.origin.x + self.buildingLabel.width + 15, self.buildingLabel.center.y - 8);

    [self.contentView addSubview:statusButton];
}

@end
